#!/usr/bin/python2.4


import constants
import db_object
import rpc_stubs
import utils


class HostBase(db_object.DbObject):

  __slots__ = ()

  @property
  def sort_key(self):
    return utils.hostname_sort_key(self.hostname)

  @property
  def state(self):
    results =[]
    if self.locked:
      results.append('locked')
    if constants.HL_TRIAGE_NEEDED in self.labels:
      results.append('triage needed')
    return results


class Host(HostBase):

  __slots__ = ()

  def __init__(self, raw_object, idle=None, **dargs):
    super(_this_Host, self).__init__(raw_object, **dargs)
    if idle is not None:
      self['idle'] = idle

  @property
  def notes(self):
    return self.attributes.get(constants.HA_NOTES)

  def set_notes(self, notes, commit=False):
    if commit:
      rpc_stubs.afe.set_host_attribute(constants.HA_NOTES, notes,
                                       hostname=self.hostname)
    if self.attributes is self['attributes']:
      self.attributes = dict(self.attributes)
    self.attributes[constants.HA_NOTES] = notes


_this_Host = Host

utils.import_site(globals())
